{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests \n",
    "from bs4 import BeautifulSoup\n",
    "for i in range(1,25):\n",
    "    resUrl = requests.get('http://gwy.rst.fujian.gov.cn/bulletin/'+str(i)) \n",
    "    # print(res.text) \n",
    "    soupUrl = BeautifulSoup(resUrl.text,'html.parser')\n",
    "    items = soupUrl.find_all('li')\n",
    "    with open('gongwuyuan.txt','a',encoding='utf-8') as file:\n",
    "        try:\n",
    "            for item in items:\n",
    "                url = item.find('a')['href']\n",
    "                resTable = requests.get(url) \n",
    "                soupTable = BeautifulSoup(resTable.text,'html.parser')\n",
    "                con = soupTable.find('tbody')\n",
    "                if con.find('毕业院校') != -1:\n",
    "                    index = con.text.replace('\\n', ' ') \n",
    "                    file.write(index)\n",
    "                else :\n",
    "                    pass\n",
    "        #         url.append(item.find('a')['href'])\n",
    "        except AttributeError :\n",
    "            pass\n",
    "    file.close()\n",
    "print('sucess')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 杨英杰  python 提取出电场仿真结果中所有参数前5%取平均\n",
    "import csv\n",
    "base_p = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.5, 3, 3.5, 5]\n",
    "base_z = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.63, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2]\n",
    "for j in base_p:\n",
    "    for i in base_z:\n",
    "            routine = r'C:/Users/GilesYang/Desktop/test for eMax/p'+str(j)+'z'+str(i)+'.txt'\n",
    "            with open(routine) as f:\n",
    "                data = f.readlines()\n",
    "\n",
    "            tmp = \"\"\n",
    "            for d in data:\n",
    "                if d.find(\"ElemSolution\") != -1:\n",
    "                    d = d.strip().strip(\"\\n\").replace(\")\",\"\").replace(\"ElemSolution(\",\"\")\n",
    "                    tmp = d\n",
    "\n",
    "            tmp = tmp.split(\",\")\n",
    "\n",
    "            tmp = [eval(i) for i in tmp]\n",
    "\n",
    "            list.sort(tmp, reverse= True)\n",
    "\n",
    "            print(len(tmp))\n",
    "\n",
    "            ind1 = int(0.001 * len(tmp) + 1)\n",
    "            tmp1 = tmp[:ind1]\n",
    "        #     print(tmp1)\n",
    "            res1 = sum(tmp1) \n",
    "        #     print(res1 / ind1)\n",
    "\n",
    "            ind2 = int(0.005 * len(tmp) + 1)\n",
    "            tmp2 = tmp[:ind2]\n",
    "            # print(tmp)\n",
    "            res2 = sum(tmp2) \n",
    "        #     print(res2 / ind2)\n",
    "\n",
    "            ind3 = int(0.01 * len(tmp) + 1)\n",
    "            tmp3 = tmp[:ind3]\n",
    "            # print(tmp)\n",
    "            res3 = sum(tmp3) \n",
    "        #     print(res3 / ind3)\n",
    "\n",
    "            ind4 = int(0.05 * len(tmp) + 1)\n",
    "            tmp4 = tmp[:ind4]\n",
    "            # print(tmp)\n",
    "            res4 = sum(tmp4) \n",
    "        #     print(res4 / ind4)\n",
    "            data = ['p='+str(j),'z='+str(i),'lenth='+str(len(tmp)),res1 / ind1,res2 / ind2,res3 / ind3,res4 / ind4,tmp[0]]\n",
    "            print(data)\n",
    "\n",
    "            with open(r\"C:/Users/GilesYang/Desktop/test for eMax/1.csv\",'a',newline = '') as file1:    \n",
    "                f_csv = csv.writer(file1)   # 实例化对象 = 模块.类(文档指针)     ②:将指针指向f_csv\n",
    "                f_csv.writerow(data)   # 对象.所需函数('内容')     ② "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "base_p = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.5, 3, 3.5, 5]\n",
    "base_z = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.63, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2]\n",
    "for j in base_p:\n",
    "    for i in base_z:\n",
    "            routine = r'C:/Users/GilesYang/Desktop/test for eMax/p'+str(j)+'z'+str(i)+'.txt'\n",
    "            with open(routine) as f:\n",
    "                print([j,i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "routine = r'C:/Users/GilesYang/Desktop/20200301 for PDIV_z0.38.txt'\n",
    "with open(routine) as f:\n",
    "    data = f.readlines()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "191303\n",
      "[33362988.020833332, 23450098.746081505, 20727558.254963428, 15913237.298766464, 108925000.0]\n"
     ]
    }
   ],
   "source": [
    "## PDIV备份\n",
    "import csv\n",
    "routine = r'C:/Users/GilesYang/Desktop/高压封装/test for eMax/20210304 for gra/PDIV6.txt'\n",
    "with open(routine) as f:\n",
    "    data = f.readlines()\n",
    "\n",
    "tmp = \"\"\n",
    "for d in data:\n",
    "    if d.find(\"ElemSolution\") != -1:\n",
    "        d = d.strip().strip(\"\\n\").replace(\")\",\"\").replace(\"ElemSolution(\",\"\")\n",
    "        tmp = d\n",
    "# for d in data:\n",
    "#     if d.find(\"ElemSolution(\") != -1:\n",
    "#         d = d.strip().strip(\"\\n\").replace(\")\",\"\").replace(\"ElemSolution(\",\"\")\n",
    "#         d, sep, tail = d.partition('ElemSolutionMinMaxLocation')\n",
    "#         tmp = d.strip()\n",
    "\n",
    "tmp = tmp.split(\",\")\n",
    "\n",
    "tmp = [eval(i) for i in tmp]\n",
    "\n",
    "list.sort(tmp, reverse= True)\n",
    "\n",
    "print(len(tmp))\n",
    "\n",
    "ind1 = int(0.001 * len(tmp) + 1)\n",
    "tmp1 = tmp[:ind1]\n",
    "#     print(tmp1)\n",
    "res1 = sum(tmp1) \n",
    "#     print(res1 / ind1)\n",
    "\n",
    "ind2 = int(0.005 * len(tmp) + 1)\n",
    "tmp2 = tmp[:ind2]\n",
    "# print(tmp)\n",
    "res2 = sum(tmp2) \n",
    "#     print(res2 / ind2)\n",
    "\n",
    "ind3 = int(0.01 * len(tmp) + 1)\n",
    "tmp3 = tmp[:ind3]\n",
    "# print(tmp)\n",
    "res3 = sum(tmp3) \n",
    "#     print(res3 / ind3)\n",
    "\n",
    "ind4 = int(0.05 * len(tmp) + 1)\n",
    "tmp4 = tmp[:ind4]\n",
    "# print(tmp)\n",
    "res4 = sum(tmp4) \n",
    "#     print(res4 / ind4)\n",
    "data = [res1 / ind1,res2 / ind2,res3 / ind3,res4 / ind4,tmp[0]]\n",
    "print(data)\n",
    "\n",
    "with open(r\"C:/Users/GilesYang/Desktop/高压封装/test for eMax/20210301.csv\",'a',newline = '') as file1:    \n",
    "    f_csv = csv.writer(file1)   # 实例化对象 = 模块.类(文档指针)     ②:将指针指向f_csv\n",
    "    f_csv.writerow(data)   # 对象.所需函数('内容')     ② "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "191303\n",
      "[33362988.020833332, 23450098.746081505, 20727558.254963428, 15913237.298766464, 108925000.0]\n"
     ]
    }
   ],
   "source": [
    "## PDIV备份\n",
    "import csv\n",
    "routine = r'C:/Users/GilesYang/Desktop/高压封装/test for eMax/20210304 for gra/PDIV6.txt'\n",
    "with open(routine) as f:\n",
    "    data = f.readlines()\n",
    "\n",
    "tmp = \"\"\n",
    "# for d in data:\n",
    "#     if d.find(\"ElemSolution\") != -1:\n",
    "#         d = d.strip().strip(\"\\n\").replace(\")\",\"\").replace(\"ElemSolution(\",\"\")\n",
    "#         tmp = d\n",
    "for d in data:\n",
    "    if d.find(\"ElemSolution(\") != -1:\n",
    "        d = d.strip().strip(\"\\n\").replace(\")\",\"\").replace(\"ElemSolution(\",\"\")\n",
    "        d, sep, tail = d.partition('ElemSolutionMinMaxLocation')\n",
    "        tmp = d.strip()\n",
    "\n",
    "tmp = tmp.split(\",\")\n",
    "\n",
    "tmp = [eval(i) for i in tmp]\n",
    "\n",
    "list.sort(tmp, reverse= True)\n",
    "\n",
    "print(len(tmp))\n",
    "\n",
    "ind1 = int(0.001 * len(tmp) + 1)\n",
    "tmp1 = tmp[:ind1]\n",
    "#     print(tmp1)\n",
    "res1 = sum(tmp1) \n",
    "#     print(res1 / ind1)\n",
    "\n",
    "ind2 = int(0.005 * len(tmp) + 1)\n",
    "tmp2 = tmp[:ind2]\n",
    "# print(tmp)\n",
    "res2 = sum(tmp2) \n",
    "#     print(res2 / ind2)\n",
    "\n",
    "ind3 = int(0.01 * len(tmp) + 1)\n",
    "tmp3 = tmp[:ind3]\n",
    "# print(tmp)\n",
    "res3 = sum(tmp3) \n",
    "#     print(res3 / ind3)\n",
    "\n",
    "ind4 = int(0.05 * len(tmp) + 1)\n",
    "tmp4 = tmp[:ind4]\n",
    "# print(tmp)\n",
    "res4 = sum(tmp4) \n",
    "#     print(res4 / ind4)\n",
    "data = [res1 / ind1,res2 / ind2,res3 / ind3,res4 / ind4,tmp[0]]\n",
    "print(data)\n",
    "with open(r\"C:/Users/GilesYang/Desktop/高压封装/test for eMax/20210302.csv\",'a',newline = '') as file1:    \n",
    "    f_csv = csv.writer(file1)   # 实例化对象 = 模块.类(文档指针)     ②:将指针指向f_csv\n",
    "    f_csv.writerow(data)   # 对象.所需函数('内容')     ② "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}